package com.aaa.controller.log;

import com.aaa.controller.BaseController;
import com.aaa.entity.PageSortEntity;
import com.aaa.entity.Result;
import com.aaa.entity.log.Log;
import com.aaa.service.log.LogService;
import com.github.pagehelper.Page;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

/**
 * (Log)表控制层
 *
 * @author makejava
 * @since 2022-09-06 14:09:22
 */
@RestController
@RequestMapping("log")
public class LogController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private LogService logService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<Log> queryById(@PathVariable("id") Integer id) {
        return ResponseEntity.ok(this.logService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param log 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<Log> add(Log log) {
        return ResponseEntity.ok(this.logService.insert(log));
    }

    /**
     * 编辑数据
     *
     * @param log 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<Log> edit(Log log) {
        return ResponseEntity.ok(this.logService.update(log));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Integer id) {
        return ResponseEntity.ok(this.logService.deleteById(id));
    }


    /**
     * 分页查询
     * @param pageSortEntity
     * @param log
     * @return
     */
    @RequestMapping("queryAllByPage.do")
    public Result queryAllByPage(PageSortEntity pageSortEntity, Log log) {
        Page<Log> page = logService.queryAllByPage(pageSortEntity,log);
        return success(page.getResult(), page.getTotal());
    }

    /**
     * 跳转
     * @param modelAndView
     * @return
     */
    @RequestMapping("toShowLog.do")
    public ModelAndView toShowLog(ModelAndView modelAndView) {
        modelAndView.setViewName("log/toShowLog");
        return modelAndView;
    }
}

